using UnityEngine;

public class PlayerSkillsScreen : UILayer
{
	public GameObject skillButton;

	public GameObject linePrefab;

	public GameObject table;

	public int columnWidth;

	public int columnHeight;

	public UIScrollView scrollView;

	private void Awake()
	{
		Init();
	}

	private void OnEnable()
	{
		TableTennisMainNavigation tableTennisMainNavigation = NavigationManager.instance as TableTennisMainNavigation;
		tableTennisMainNavigation.characterView.ShowUIBackground();
		tableTennisMainNavigation.characterView.ShowCarbonPanel(false);
		tableTennisMainNavigation.SetHeader(TableTennisMainNavigation.HeaderType.None);
	}

	private void Init()
	{
		PlayerSkills instance = ScriptableObjectSingleton<PlayerSkills>.instance;
		PlayerSkillButton playerSkillButton = null;
		foreach (PlayerSkills.SkillItem skill in instance.skills)
		{
			UIWidget component = NGUITools.AddChild(table.gameObject, skillButton).GetComponent<UIWidget>();
			component.cachedGameObject.SetActive(true);
			PlayerSkillButton component2 = component.GetComponent<PlayerSkillButton>();
			component2.Init(skill);
			PositionWidget(skill.column, skill.row, component);
			if (skill.isActive && !skill.isPassed && playerSkillButton == null)
			{
				playerSkillButton = component2;
			}
			PlayerSkills.SkillItem item = skill.prev.item;
			if (item != null)
			{
				UISprite component3 = NGUITools.AddChild(table, linePrefab).GetComponent<UISprite>();
				UITools.SetActive(component3, true);
				UITools.LineLocalSpace(component3, Position(skill), Position(item));
			}
		}
		StopAllCoroutines();
		if (playerSkillButton != null)
		{
			UITools.CenterWidgetOnScroll(playerSkillButton.GetComponent<UIWidget>(), scrollView);
		}
	}

	private Vector3 Position(PlayerSkills.SkillItem item)
	{
		return new Vector3(item.column * columnWidth, item.row * columnHeight, 0f);
	}

	private Vector3 Position(int col, int row)
	{
		return new Vector3(col * columnWidth, row * columnHeight, 0f);
	}

	private void PositionWidget(int col, int row, UIWidget widget)
	{
		widget.transform.localPosition = Position(col, row);
	}
}
